package com.epoint.mobileoa.personalized.epointcompany.ui.gzrz;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import android.content.Intent;
import android.view.View;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.SimpleAdapter;

import com.epoint.mobileoa.R;
import com.epoint.mobileoa.bizlogic.SuperView;
import com.epoint.mobileoa.personalized.epointcompany.ui.PersonalRiziListView;
import com.epoint.mobileoa.tools.ToastHelp;

/**
 * @author liyc
 * @time 2012-7-18 下午2:35:04
 * @annotation 工作日志主界面
 */
public class GzrzMainView extends SuperView {

	private GridView gv;
	@Override
	public void initControls() {
		gv = (GridView) findViewById(R.id.gv);
		gv.setOnItemClickListener(this);
		String[] titles = new String[]{"我的日志","日志审核"};
		gv.setAdapter(getAdapter(titles));
	}

	@Override
	public void onItemClick(AdapterView<?> parent, View view,
			int position, long id) {
		if(position==0){
			Intent it = new Intent(this, PersonalRiziListView.class);
			startActivity(it);
		}
		else if(position==1){
			ToastHelp.showToast(this, "此功能暂未开放");
		}
	}

	@Override
	public void refresh(Object... param) {

	}

	@Override
	public String setTitle() {
		return "工作日志";
	}

	@Override
	public int getLayoutInt() {
		return R.layout.gzrzmain;
	}

	public SimpleAdapter getAdapter(String[] titles){
		int[] imgs = new int[] { R.drawable.img_wdrz, R.drawable.img_rzsh};
		List<Map<String, Object>> listItems = new ArrayList<Map<String, Object>>();
		for (int i = 0; i < imgs.length; i++) {
			Map<String, Object> mapItem = new HashMap<String, Object>();
			mapItem.put("img", imgs[i]);
			mapItem.put("title", titles[i]);
			listItems.add(mapItem);
		}

		int iconlayout;
		if(getBackgroundStr().equals("white")){
			iconlayout = R.layout.gvicon;
		}
		else{
			iconlayout = R.layout.gvicon_white;
		}

		SimpleAdapter sa = new SimpleAdapter(this, listItems, iconlayout,
				new String[] { "img", "title" }, new int[] { R.id.gvicon_img,
				R.id.gvicon_title });
		return sa;
	}

	@Override
	public void refreshForNewTask(int TaskId,Object... param){
	}

}
